<template>
  <el-dialog title="毕业选择" :visible.sync="dialogVisible" @close="$emit('update:visible',false)" width="40%">
    <!--checkType 1 查看详情 2 编辑-->
    <div class="dialog_conwrap">
      <el-form label-width="100px" ref="editForm">
        <el-form-item label="" >
          本届班级毕业
        </el-form-item>
        <el-form-item label="毕业时间：" >
          <el-date-picker
                  v-model="value1"
                  type="date"
                  placeholder="选择日期"
                  value-format="yyyy-MM-dd">
          </el-date-picker>
        </el-form-item>
      </el-form>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button @click="dialogVisible=false" size="small">取消</el-button>
      <el-button type="primary" size="small" @click="saveFrom">确定并提交毕业</el-button>
    </span>
  </el-dialog>
</template>

<script>
  import api from '@/utils/api.js'

  export default {
    name: 'uploadClass',
    props: ['visible', 'segmentId', 'section_name'],
    data () {
      return {
        dialogVisible: false,
        value1: ''
      }
    },
    watch: {
      visible () {
        this.dialogVisible = this.visible
      }
    },
    methods: {
      saveFrom () {
        console.log('value1:', this.value1)
        if (!this.value1) {
          this.$message.error('请选择毕业时间！')
          return
        }
        let self_ = this
        this.$confirm('此操作将本校' + this.section_name + '学生,在' + this.value1 + '予以毕业, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$post(api.new_semester_finish, {id: self_.segmentId, time: self_.value1}).then((response) => {
            if (response.code === 0) {
              self_.$emit('refreshFn')
              self_.dialogVisible = false
              self_.value1 = ''
              self_.$message({
                message: '操作成功',
                type: 'success'
              })
            } else {
              self_.$message.error(response.msg)
            }
          }).catch((err) => {
            console.log(err)
          })
        }).catch(() => {
        })
      }
    }
  }
</script>
